package com.uwosh.cs342.g6.mapapp;

import org.json.JSONObject;


public class SearchResult
{
	// these are obtained through places auto complete call
	public String reference = "";
	public String address = "";
	public String name = "";
	public String phone = "";
	public String icon = "";
	public double longitude = -1;
	public double latitude = -1;
	
	
	// these are obtained through places details call
	
	
	public SearchResult(JSONObject result)
	{
		parseResult(result);
	}
	
	
	public void parseResult(JSONObject result)
	{
		try
		{
			this.reference = result.getString("reference");
			this.address = result.getString("formatted_address");
			this.name = result.getString("name");
			this.phone = result.getString("formatted_phone_number");
			this.icon = result.getString("icon");
			JSONObject geoArray = result.getJSONObject("geometry");
			JSONObject location = geoArray.getJSONObject("location");
			this.longitude = location.getDouble("lng");
			this.latitude = location.getDouble("lat");
		}
		catch(Exception e)
		{
			System.out.println("ERROR ERROR ERROR!!");
		}
	}
	
	
	public String toString()
	{
		return "Reference: " + this.reference + "\n" +
			   "Address: " + this.address + "\n" +
			   "Name: " + this.name + "\n" +
			   "Phone: " + this.phone + "\n" +
			   "Icon: " + this.icon + "\n" +
			   "Longitude: " + this.longitude + "\n" +
			   "Latitude: " + this.latitude;
	}
	
}
